;
(function ($) {
    $.ajaxPlugin = function (options) {
        var defaultConfig = {
            contentType:'text/html',
            error: function (a, b, c) {
                if ((a.responseText && eval(
                        '(' + a.responseText + ')').noLogin) || a.status == 403) {
                    var str = eval('(' + a.responseText + ')');
                    /*layer.alert("检测到未登录，请重新登录", function () {
                     location.href = "logout";
                     });*/
                    layer.open({
                                   title: "检测到未登录，请重新登录",
                                   content: "<div class='ui form overTimeRight'><div class= 'inline field userName'><label>用户名</label><input type = 'text'></div><div class= 'inline field userPwd'><label>密码</label><input type = 'password'></div> </div>",
                                   yes: function (index) {
                                       $.ajax({
                                                  url: '/login',
                                                  data: {
                                                      "userName": $(".userName input:text").val(),
                                                      "pwd": $(".userPwd input:password").val()
                                                  },
                                                  type: 'post',
                                                  dataType: 'json',
                                                  success: function (data) {
                                                      layer.close(index);
                                                  }
                                              });

                                   }
                               }
                    );
                } else {
                    if (options.error) {
                        options.error.call(this, a, b, c);
                    }
                }
            }
        };
        var settings = $.extend(true, {}, options, defaultConfig);
        $.ajax({
                   url: settings.url,
                   type: settings.type,
                   data: settings.data,
                   contentType: setting.contentType,
                   method: settings.method ? settings.method : 'post',
                   dataType: settings.dataType,
                   beforeSend: settings.beforeSend,
                   complete: settings.complete,
                   success: settings.success,
                   error: settings.error
               });
    };
})(jQuery);
